/*
* Copyright (c) 2008, Vladimir Gumenuk
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the copyright holder nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// BankNamesDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RealGNX4Lib.h"
#include "BankNamesDlg.h"


// CBankNamesDlg dialog

IMPLEMENT_DYNAMIC(CBankNamesDlg, CDialog)

CBankNamesDlg::CBankNamesDlg( GNX4TblHdr *pHdr, CWnd* pParent /*=NULL*/)
	: CDialog(CBankNamesDlg::IDD, pParent)
{
    ASSERT( pHdr );
    m_pHdr = pHdr;
    m_csBank1  = pHdr->szBankName1;
    m_csBank2  = pHdr->szBankName2;
    m_csBank3  = pHdr->szBankName3;
    m_csBank4  = pHdr->szBankName4;
    m_csBank5  = pHdr->szBankName5;
    m_csBank6  = pHdr->szBankName6;
    m_csBank7  = pHdr->szBankName7;
    m_csBank8  = pHdr->szBankName8;
    m_csBank9  = pHdr->szBankName9;
    m_csBank10 = pHdr->szBankName10;
    m_csBank11 = pHdr->szBankName11;
    m_csBank12 = pHdr->szBankName12;
    m_csBank13 = pHdr->szBankName13;
    m_csBank14 = pHdr->szBankName14;
    m_csBank15 = pHdr->szBankName15;
    m_csBank16 = pHdr->szBankName16;
    m_bModified = FALSE;
}

CBankNamesDlg::~CBankNamesDlg()
{
}

void CBankNamesDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_BANKNAME_EDIT1, m_csBank1);
    DDV_MaxChars(pDX, m_csBank1, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT2, m_csBank2);
	DDV_MaxChars(pDX, m_csBank2, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT3, m_csBank3);
    DDV_MaxChars(pDX, m_csBank3, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT4, m_csBank4);
    DDV_MaxChars(pDX, m_csBank4, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT5, m_csBank5);
    DDV_MaxChars(pDX, m_csBank5, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT6, m_csBank6);
    DDV_MaxChars(pDX, m_csBank6, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT7, m_csBank7);
    DDV_MaxChars(pDX, m_csBank7, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT8, m_csBank8);
    DDV_MaxChars(pDX, m_csBank8, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT9, m_csBank9);
    DDV_MaxChars(pDX, m_csBank9, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT10, m_csBank10);
    DDV_MaxChars(pDX, m_csBank10, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT11, m_csBank11);
    DDV_MaxChars(pDX, m_csBank11, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT12, m_csBank12);
    DDV_MaxChars(pDX, m_csBank12, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT13, m_csBank13);
    DDV_MaxChars(pDX, m_csBank13, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT14, m_csBank14);
    DDV_MaxChars(pDX, m_csBank14, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT15, m_csBank15);
    DDV_MaxChars(pDX, m_csBank15, 10);
    DDX_Text(pDX, IDC_BANKNAME_EDIT16, m_csBank16);
    DDV_MaxChars(pDX, m_csBank16, 10);
}


BEGIN_MESSAGE_MAP(CBankNamesDlg, CDialog)
END_MESSAGE_MAP()


// CBankNamesDlg message handlers

void CBankNamesDlg::OnOK()
{
    UpdateData();

    CString *pStr = &m_csBank1;
    for( int i = 0; i < 16; i++ )
    {
        if( pStr->IsEmpty() )
            return;
        pStr++;
    }

    pStr = &m_csBank1;
    CHAR *pszBnk = &m_pHdr->szBankName1[0];
    CHAR szBuf[GNX_MAXNAME_LEN+1];

    for( int i = 0; i < 16; i++ )
    {
        StoreGNXStringA( szBuf, *pStr );

        if( strcmp( pszBnk, szBuf  ) != 0 )
        {
            strcpy( pszBnk, szBuf );
            m_bModified = TRUE;
        }

        pStr++;
        pszBnk += 12;
    }
    
    CDialog::OnOK();
}